<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta name="generator" content="Docusaurus v2.0.0-alpha.70">
<link rel="alternate" type="application/rss+xml" href="/blog/rss.xml" title="Furion Blog RSS Feed">
<link rel="alternate" type="application/atom+xml" href="/blog/atom.xml" title="Furion Blog Atom Feed">
<link rel="search" type="application/opensearchdescription+xml" title="Furion" href="/opensearch.xml"><title data-react-helmet="true">Blog | Furion</title><meta data-react-helmet="true" property="og:title" content="Blog | Furion"><meta data-react-helmet="true" name="description" content="Blog"><meta data-react-helmet="true" property="og:description" content="Blog"><meta data-react-helmet="true" name="twitter:card" content="summary_large_image"><meta data-react-helmet="true" name="docsearch:language" content="en"><meta data-react-helmet="true" name="docsearch:docusaurus_tag" content="default"><link data-react-helmet="true" rel="shortcut icon" href="/img/favicon.ico"><link data-react-helmet="true" rel="preconnect" href="https://BH4D9OD16A-dsn.algolia.net" crossorigin="anonymous"><link rel="stylesheet" href="/styles.13d8b9ba.css">
<link rel="preload" href="/styles.ea68ff99.js" as="script">
<link rel="preload" href="/runtime~main.50cd4803.js" as="script">
<link rel="preload" href="/main.ac3b1c78.js" as="script">
<link rel="preload" href="/1.0da20ad4.js" as="script">
<link rel="preload" href="/2.7055f5a8.js" as="script">
<link rel="preload" href="/01a85c17.7b7465e8.js" as="script">
<link rel="preload" href="/1be78505.1a275235.js" as="script">
<link rel="preload" href="/6875c492.a02cc87e.js" as="script">
<link rel="preload" href="/a6aa9e1f.52c68dae.js" as="script">
<link rel="preload" href="/ccc49370.62ea357d.js" as="script">
<link rel="preload" href="/ece76bd1.fe42441a.js" as="script">
<link rel="preload" href="/122.f76c89cd.js" as="script">
<link rel="preload" href="/1f1c7772.647301f8.js" as="script">
<link rel="preload" href="/34087545.107d9503.js" as="script">
<link rel="preload" href="/5048ccdb.44eb3ecd.js" as="script">
<link rel="preload" href="/d3c206bc.4f55d22c.js" as="script">
<link rel="preload" href="/5c4ee1d6.17a5debf.js" as="script">
</head>
<body>
<script>!function(){function t(t){document.documentElement.setAttribute("data-theme",t)}var e=function(){var t=null;try{t=localStorage.getItem("theme")}catch(t){}return t}();t(null!==e?e:"light")}()</script><div id="__docusaurus">
<div class="furion-give-me-star">⭐️ 如果你喜欢 <a href="https://gitee.com/dotnetchina/Furion" target="_blank">Furion</a> ，可以在 <a href="https://gitee.com/dotnetchina/Furion" target="_blank">Gitee</a> 中给个<a href="https://gitee.com/dotnetchina/Furion" target="_blank"><img class="furion-gitee-star" src="https://gitee.com/dotnetchina/Furion/badge/star.svg?theme=gvp" alt="star"></a> ⭐️</div><nav aria-label="Skip navigation links"><button type="button" tabindex="0" class="skipToContent_11B0">Skip to main content</button></nav><nav class="navbar navbar--fixed-top navbarHideable_17Wu navbarHidden_19ww"><div class="navbar__inner"><div class="navbar__items"><div aria-label="Navigation bar toggle" class="navbar__toggle" role="button" tabindex="0"><svg aria-label="Menu" width="30" height="30" viewBox="0 0 30 30" role="img" focusable="false"><title>Menu</title><path stroke="currentColor" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2" d="M4 7h22M4 15h22M4 23h22"></path></svg></div><a class="navbar__brand" href="/"><img src="/img/furionlogo.png" alt="Furion Logo" class="themedImage_YANc themedImage--light_3CMI navbar__logo"><img src="/img/furionlogo.png" alt="Furion Logo" class="themedImage_YANc themedImage--dark_3ARp navbar__logo"><strong class="navbar__title">Furion</strong></a><a class="navbar__item navbar__link" href="/docs">文档</a><a class="navbar__item navbar__link" href="/docs/global/app">静态类</a><a class="navbar__item navbar__link" href="/docs/settings/appsettings">配置</a><a aria-current="page" class="navbar__item navbar__link navbar__link--active" href="/blog">博客</a><a class="navbar__item navbar__link" href="/docs/upgrade">更新日志✨</a></div><div class="navbar__items navbar__items--right"><div class="navbar__item dropdown dropdown--hoverable dropdown--right"><a class="navbar__item navbar__link">源码</a><ul class="dropdown__menu"><li><a href="https://gitee.com/dotnetchina/Furion" target="_blank" rel="noopener noreferrer" class="dropdown__link">Gitee</a></li><li><a href="https://github.com/MonkSoul/Furion" target="_blank" rel="noopener noreferrer" class="dropdown__link">GitHub</a></li></ul></div><a href="https://www.chinadot.net" target="_blank" rel="noopener noreferrer" class="navbar__item navbar__link">社区</a><a class="navbar__item navbar__link" href="/docs/cooperate">合作</a><a class="navbar__item navbar__link" href="/docs/donate">赞助</a><div class="react-toggle react-toggle--disabled displayOnlyInLargeViewport_2N3Q"><div class="react-toggle-track"><div class="react-toggle-track-check"><span class="toggle_3NWk">🌜</span></div><div class="react-toggle-track-x"><span class="toggle_3NWk">🌞</span></div></div><div class="react-toggle-thumb"></div><input type="checkbox" disabled="" aria-label="Dark mode toggle" class="react-toggle-screenreader-only"></div><button type="button" class="DocSearch DocSearch-Button" aria-label="Search"><div class="DocSearch-Button-Container"><svg width="20" height="20" class="DocSearch-Search-Icon" viewBox="0 0 20 20"><path d="M14.386 14.386l4.0877 4.0877-4.0877-4.0877c-2.9418 2.9419-7.7115 2.9419-10.6533 0-2.9419-2.9418-2.9419-7.7115 0-10.6533 2.9418-2.9419 7.7115-2.9419 10.6533 0 2.9419 2.9418 2.9419 7.7115 0 10.6533z" stroke="currentColor" fill="none" fill-rule="evenodd" stroke-linecap="round" stroke-linejoin="round"></path></svg><span class="DocSearch-Button-Placeholder">Search</span></div></button></div></div><div role="presentation" class="navbar-sidebar__backdrop"></div><div class="navbar-sidebar"><div class="navbar-sidebar__brand"><a class="navbar__brand" href="/"><img src="/img/furionlogo.png" alt="Furion Logo" class="themedImage_YANc themedImage--light_3CMI navbar__logo"><img src="/img/furionlogo.png" alt="Furion Logo" class="themedImage_YANc themedImage--dark_3ARp navbar__logo"><strong class="navbar__title">Furion</strong></a></div><div class="navbar-sidebar__items"><div class="menu"><ul class="menu__list"><li class="menu__list-item"><a class="menu__link" href="/docs">文档</a></li><li class="menu__list-item"><a class="menu__link" href="/docs/global/app">静态类</a></li><li class="menu__list-item"><a class="menu__link" href="/docs/settings/appsettings">配置</a></li><li class="menu__list-item"><a aria-current="page" class="menu__link navbar__link--active" href="/blog">博客</a></li><li class="menu__list-item"><a class="menu__link" href="/docs/upgrade">更新日志✨</a></li><li class="menu__list-item menu__list-item--collapsed"><a role="button" class="menu__link menu__link--sublist">源码</a><ul class="menu__list"><li class="menu__list-item"><a href="https://gitee.com/dotnetchina/Furion" target="_blank" rel="noopener noreferrer" class="menu__link">Gitee</a></li><li class="menu__list-item"><a href="https://github.com/MonkSoul/Furion" target="_blank" rel="noopener noreferrer" class="menu__link">GitHub</a></li></ul></li><li class="menu__list-item"><a href="https://www.chinadot.net" target="_blank" rel="noopener noreferrer" class="menu__link">社区</a></li><li class="menu__list-item"><a class="menu__link" href="/docs/cooperate">合作</a></li><li class="menu__list-item"><a class="menu__link" href="/docs/donate">赞助</a></li></ul></div></div></div></nav><div class="main-wrapper blog-wrapper"><div class="container margin-vert--lg"><div class="row"><div class="col col--2"><div class="sidebar_SWld thin-scrollbar"><h3 class="sidebarItemTitle_Km2m">Recent posts</h3><ul class="sidebarItemList_3UpA"><li class="sidebarItem_2T0D"><a class="sidebarItemLink_v5H9" href="/blog/fileupload-download">3. 文件上传下载</a></li><li class="sidebarItem_2T0D"><a class="sidebarItemLink_v5H9" href="/blog/httpcontext">2. HttpContext 应用</a></li><li class="sidebarItem_2T0D"><a class="sidebarItemLink_v5H9" href="/blog/welcome">1. Furion 介绍</a></li></ul></div></div><main class="col col--8"><article class="margin-bottom--xl"><header><h2 class="margin-bottom--sm blogPostTitle_3-lP"><a href="/blog/fileupload-download">3. 文件上传下载</a></h2><div class="margin-vert--md"><time datetime="2021-02-02T00:00:00.000Z" class="blogPostDate_Ta7i">February 2, 2021  · 1 min read</time></div><div class="avatar margin-vert--md"><a class="avatar__photo-link avatar__photo" href="https://www.chinadot.net" target="_blank" rel="noreferrer noopener"><img src="https://i.loli.net/2021/01/19/M8q5a3OTZWUKicl.png" alt="dotNET China"></a><div class="avatar__intro"><h4 class="avatar__name"><a href="https://www.chinadot.net" target="_blank" rel="noreferrer noopener">dotNET China</a></h4><small class="avatar__subtitle">为中国 .NET 开发者提供优质的资讯和技术分享。</small></div></div></header><section class="markdown"><h2><a aria-hidden="true" tabindex="-1" class="anchor" id="文件下载"></a>文件下载<a class="hash-link" href="#文件下载" title="Direct link to heading">#</a></h2><div class="mdxCodeBlock_1zKU"><div class="codeBlockContent_actS"><div tabindex="0" class="prism-code language-cs codeBlock_tuNs thin-scrollbar"><div class="codeBlockLines_3uvA" style="color:#bfc7d5;background-color:#292d3e"><div class="token-line" style="color:#bfc7d5"><span class="token plain">[HttpGet, NonUnify]</span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain">public IActionResult FileDownload(string path, string fileName)</span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain">{</span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain">    string filePath = Path.GetFullPath(&quot;~/temp/&quot;).Replace(&quot;~\\&quot;, &quot;&quot;) + path;</span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain">    return new FileStreamResult(new FileStream(filePath, FileMode.Open), &quot;application/octet-stream&quot;) { FileDownloadName = fileName };</span></div><div class="token-line" style="color:#bfc7d5"><span class="token plain">}</span></div></div></div><button type="button" aria-label="Copy code to clipboard" class="copyButton_2GIj">Copy</button></div></div></section><footer class="row margin-vert--lg"><div class="col"><strong>Tags:</strong><a class="margin-horiz--sm" href="/blog/tags/furion">furion</a><a class="margin-horiz--sm" href="/blog/tags/furos">furos</a><a class="margin-horiz--sm" href="/blog/tags/net">.net</a><a class="margin-horiz--sm" href="/blog/tags/netcore">.netcore</a><a class="margin-horiz--sm" href="/blog/tags/net-5">.net5</a><a class="margin-horiz--sm" href="/blog/tags/upload">upload</a><a class="margin-horiz--sm" href="/blog/tags/download">download</a></div><div class="col text--right"><a aria-label="Read more about 3. 文件上传下载" href="/blog/fileupload-download"><strong>Read More</strong></a></div></footer></article><article class="margin-bottom--xl"><header><h2 class="margin-bottom--sm blogPostTitle_3-lP"><a href="/blog/httpcontext">2. HttpContext 应用</a></h2><div class="margin-vert--md"><time datetime="2021-02-01T00:00:00.000Z" class="blogPostDate_Ta7i">February 1, 2021  · 1 min read</time></div><div class="avatar margin-vert--md"><a class="avatar__photo-link avatar__photo" href="https://www.chinadot.net" target="_blank" rel="noreferrer noopener"><img src="https://i.loli.net/2021/01/19/M8q5a3OTZWUKicl.png" alt="dotNET China"></a><div class="avatar__intro"><h4 class="avatar__name"><a href="https://www.chinadot.net" target="_blank" rel="noreferrer noopener">dotNET China</a></h4><small class="avatar__subtitle">为中国 .NET 开发者提供优质的资讯和技术分享。</small></div></div></header><section class="markdown"><h2><a aria-hidden="true" tabindex="-1" class="anchor" id="httpcontext-重大调整"></a>HttpContext 重大调整<a class="hash-link" href="#httpcontext-重大调整" title="Direct link to heading">#</a></h2><p>在 <code>ASP.NET</code> 的时代，我们通常通过 <code>HttpContext</code> 全局静态类获取请求上下文，但在 <code>ASP.NET Core</code> 中，<code>HttpContext</code> 是一个非静态的抽象类，无法手动创建，也无法通过静态获取。</p><p>虽然在 <code>ASP.NET Core</code> 中无法直接获取 <code>HttpContext</code> 对象。但是微软也提供了注入 <code>IHttpContextAccessor</code> 方式获取。</p><h2><a aria-hidden="true" tabindex="-1" class="anchor" id="httpcontext-多种获取方式"></a>HttpContext 多种获取方式<a class="hash-link" href="#httpcontext-多种获取方式" title="Direct link to heading">#</a></h2></section><footer class="row margin-vert--lg"><div class="col"><strong>Tags:</strong><a class="margin-horiz--sm" href="/blog/tags/furion">furion</a><a class="margin-horiz--sm" href="/blog/tags/furos">furos</a><a class="margin-horiz--sm" href="/blog/tags/net">.net</a><a class="margin-horiz--sm" href="/blog/tags/netcore">.netcore</a><a class="margin-horiz--sm" href="/blog/tags/net-5">.net5</a><a class="margin-horiz--sm" href="/blog/tags/httpcontext">httpcontext</a></div><div class="col text--right"><a aria-label="Read more about 2. HttpContext 应用" href="/blog/httpcontext"><strong>Read More</strong></a></div></footer></article><article class="margin-bottom--xl"><header><h2 class="margin-bottom--sm blogPostTitle_3-lP"><a href="/blog/welcome">1. Furion 介绍</a></h2><div class="margin-vert--md"><time datetime="2020-08-19T00:00:00.000Z" class="blogPostDate_Ta7i">August 19, 2020  · 9 min read</time></div><div class="avatar margin-vert--md"><a class="avatar__photo-link avatar__photo" href="https://www.chinadot.net" target="_blank" rel="noreferrer noopener"><img src="https://i.loli.net/2021/01/19/M8q5a3OTZWUKicl.png" alt="dotNET China"></a><div class="avatar__intro"><h4 class="avatar__name"><a href="https://www.chinadot.net" target="_blank" rel="noreferrer noopener">dotNET China</a></h4><small class="avatar__subtitle">为中国 .NET 开发者提供优质的资讯和技术分享。</small></div></div></header><section class="markdown"><img src="/img/furionlogo.png" height="80" style="margin:0 auto;display:block"><div style="text-align:center;margin-top:25px"><p><a href="https://gitee.com/dotnetchina/Furion/stargazers" target="_blank" rel="noopener noreferrer"><img src="https://gitee.com/dotnetchina/Furion/badge/star.svg?theme=gvp" alt="star"></a> <a href="https://gitee.com/dotnetchina/Furion/members" target="_blank" rel="noopener noreferrer"><img src="https://gitee.com/dotnetchina/Furion/badge/fork.svg?theme=gvp" alt="fork"></a> <a href="https://github.com/MonkSoul/Furion/stargazers" target="_blank" rel="noopener noreferrer"><img src="https://img.shields.io/github/stars/MonkSoul/Furion?logo=github" alt="GitHub stars"></a> <a href="https://github.com/MonkSoul/Furion/network" target="_blank" rel="noopener noreferrer"><img src="https://img.shields.io/github/forks/MonkSoul/Furion?logo=github" alt="GitHub forks"></a> <a href="https://github.com/MonkSoul/Furion/blob/main/LICENSE" target="_blank" rel="noopener noreferrer"><img src="https://img.shields.io/github/license/MonkSoul/Furion" alt="GitHub license"></a> <a href="https://www.nuget.org/packages/Furion" target="_blank" rel="noopener noreferrer"><img src="https://img.shields.io/nuget/v/Furion.svg?cacheSeconds=10800" alt="nuget"></a></p></div><div style="text-align:center"><p>让 .NET 开发更简单，更通用，更流行。</p></div><img src="/img/gvp.png"><h2><a aria-hidden="true" tabindex="-1" class="anchor" id="-序言"></a>💐 序言<a class="hash-link" href="#-序言" title="Direct link to heading">#</a></h2><blockquote><p>无私奉献不是天方夜谭，有时候，我们也可以做到。</p></blockquote></section><footer class="row margin-vert--lg"><div class="col"><strong>Tags:</strong><a class="margin-horiz--sm" href="/blog/tags/furion">furion</a><a class="margin-horiz--sm" href="/blog/tags/furos">furos</a><a class="margin-horiz--sm" href="/blog/tags/net">.net</a><a class="margin-horiz--sm" href="/blog/tags/netcore">.netcore</a><a class="margin-horiz--sm" href="/blog/tags/net-5">.net5</a></div><div class="col text--right"><a aria-label="Read more about 1. Furion 介绍" href="/blog/welcome"><strong>Read More</strong></a></div></footer></article><nav class="pagination-nav" aria-label="Blog list page navigation"><div class="pagination-nav__item"></div><div class="pagination-nav__item pagination-nav__item--next"></div></nav></main></div></div></div><footer class="footer footer--dark"><div class="container"><div class="row footer__links"><div class="col footer__col"><h4 class="footer__title">文档</h4><ul class="footer__items"><li class="footer__item"><a class="footer__link-item" href="/docs/get-start">入门</a></li><li class="footer__item"><a class="footer__link-item" href="/docs">指南</a></li></ul></div><div class="col footer__col"><h4 class="footer__title">社区</h4><ul class="footer__items"><li class="footer__item"><a href="https://gitee.com/dotnetchina/Furion/issues" target="_blank" rel="noopener noreferrer" class="footer__link-item">讨论</a></li><li class="footer__item"><a href="https://gitee.com/dotnetchina/Furion/board" target="_blank" rel="noopener noreferrer" class="footer__link-item">看板</a></li></ul></div><div class="col footer__col"><h4 class="footer__title">更多</h4><ul class="footer__items"><li class="footer__item"><a class="footer__link-item" href="/blog">博客</a></li><li class="footer__item"><a href="https://gitee.com/dotnetchina/Furion" target="_blank" rel="noopener noreferrer" class="footer__link-item">仓库</a></li></ul></div></div><div class="footer__bottom text--center"><div class="margin-bottom--sm"><a href="https://www.chinadot.net/" target="_blank" rel="noopener noreferrer" class="footerLogoLink_3L_r"><img class="footer__logo" src="/img/chinadotnet.png" style="background:#fff;padding:5px 10px"></a></div><div class="footer__copyright">Copyright © 2020-2021 Furion, Baiqian Co.,Ltd.</div></div></div></footer><div class="furion-join-group"><button>加入 dotNET China 交流群</button></div></div>
<script src="/styles.ea68ff99.js"></script>
<script src="/runtime~main.50cd4803.js"></script>
<script src="/main.ac3b1c78.js"></script>
<script src="/1.0da20ad4.js"></script>
<script src="/2.7055f5a8.js"></script>
<script src="/01a85c17.7b7465e8.js"></script>
<script src="/1be78505.1a275235.js"></script>
<script src="/6875c492.a02cc87e.js"></script>
<script src="/a6aa9e1f.52c68dae.js"></script>
<script src="/ccc49370.62ea357d.js"></script>
<script src="/ece76bd1.fe42441a.js"></script>
<script src="/122.f76c89cd.js"></script>
<script src="/1f1c7772.647301f8.js"></script>
<script src="/34087545.107d9503.js"></script>
<script src="/5048ccdb.44eb3ecd.js"></script>
<script src="/d3c206bc.4f55d22c.js"></script>
<script src="/5c4ee1d6.17a5debf.js"></script>
</body>
</html>